#include<bits/stdc++.h>
using namespace std;
const int N = 5e4+10;
int idx[N];
int a[N];
int px[N],py[N];
inline bool cmp1(int x,int y){
    return px[x] < px[y];
}
inline bool cmp2(int x,int y){
    return py[x] < py[y];
}
struct qv{
    int a,b,c;
    inline bool chk(int x,int y) const{
        return 1ll*a*x + 1ll*b*y < c;
    }
};
struct KDT{
    struct zone{
        int x1,x2,y1,y2;
        friend zone operator+(zone A,zone B){
            return {min(A.x1,B.x1),max(A.x2,B.x2),min(A.y1,B.y1),max(A.y2,B.y2)};
        }
    };
    zone zs[N];
    int ls[N],rs[N];
    long long sum[N];
    int build(int l,int r,int p){
        if(r < l){
            return 0;
        }
        if(l == r){
            int now = idx[l];
            sum[now] = a[now];
            zs[now] = {px[now],px[now],py[now],py[now]};
            return now;
        }
        int mid = (l + r)/2;
        if(p){
            nth_element(idx + l,idx + mid,idx + r,cmp1);
        }else{
            nth_element(idx + l,idx + mid,idx + r,cmp2);
        }
        int now = idx[mid];
        ls[now] = build(l,mid - 1,(p + 1)%2);
        rs[now] = build(mid+1,r,(p + 1)%2);
        if(!ls[now] || !rs[now]){
            zs[now] = zs[ls[now] + rs[now]];        
        }else{
            zs[now] = zs[ls[now]] + zs[rs[now]];
        }
        zs[now] = zs[now] + (zone){px[now],px[now],py[now],py[now]};
        sum[now] = sum[ls[now]] + sum[rs[now]] + a[now];
        return now;
    }
    inline bool inner(const qv &a,const zone &b){
        return a.chk(b.x1,b.y1) && a.chk(b.x2,b.y1) && a.chk(b.x1,b.y2) && a.chk(b.x2,b.y2);
    }
    inline bool usf(const qv &a,const zone &b){
        return a.chk(b.x1,b.y1) || a.chk(b.x2,b.y1) || a.chk(b.x1,b.y2) || a.chk(b.x2,b.y2);
    }
    long long query(int now,const qv &in){
        if(inner(in,zs[now])){
            return sum[now];
        }
        long long res = 0;
        if(1ll*px[now]*in.a + 1ll*py[now]*in.b < in.c){
            res += a[now];
        }
        if(ls[now] && usf(in,zs[ls[now]])){
            res += query(ls[now],in);
        }  
        if(rs[now] && usf(in,zs[rs[now]])){
            res += query(rs[now],in); 
        }
        return res;
    }

}kdt;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int q;
    cin>>q;
    for(int i = 1;i<=n;i++){
        cin>>px[i]>>py[i]>>a[i];
        idx[i] = i;
    }
    int rot = kdt.build(1,n,0);
    for(int i = 1;i <= q;i++){
        int a,b,c;
        cin>>a>>b>>c;
        cout<<kdt.query(rot,{a,b,c})<<'\n';
    }
}